<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    // 反转字符串
    // var str = 'abcdefg'
    // 要求结果
    // gfedcba
    var str = 'abcdefg'
    var res = ""
    for (var i = str.length - 1; i > 0; i--) {
      res += str[i]
    }
    console.log(res); //gfedcb
  </script>
</body>

</html>